package com.lqian.service;

import com.lqian.config.WeixinPayProperties;
import com.lqian.controller.LogController;
import com.lqian.pojo.Course;
import com.lqian.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j //  Slf4j 作用相当于   @Autowired
//                          private static final Logger log = LoggerFactory.getLogger(WeixinPayService.class);
public class WeixinPayService {
    // 初始化一个日志对象
//    @Autowired
//    private static final Logger log = LoggerFactory.getLogger(WeixinPayService.class);

    @Value("${ksd.weixin.appid}")
    private String appid;
    @Value("${ksd.weixin.mcid}")
    private String mcid;
    @Value("${ksd.weixin.callbackurl}")
    private String callbackurl;
    @Value("${ksd.weixin.apisecret}")
    private String apisecret;
    @Value("${spring.profiles.active}")
    private String profiles;


    @Autowired
    private WeixinPayProperties weixinPayProperties;


    public void testValue(){
        System.out.println(weixinPayProperties.getAppid());
        System.out.println(weixinPayProperties.getMcid());
        System.out.println(weixinPayProperties.getCallbackurl());
        System.out.println(weixinPayProperties.getApisecret());
    }

    /**
     *用户支付课程
     */
    public void payCourse(User user, Course course){
        try{
            log.info("当前支付的用户是:{},支付的课程是:{},金额是:{}",
                    user.getUid(),course.getCourseTitle(),course.getCoursePrice());
            log.info("支付的appid是:{},回调地址是：{}", weixinPayProperties.getAppid(),
                    weixinPayProperties.getCallbackurl());
        }catch (Exception e){
            log.error("支付出异常，异常信息是:{}", e.getMessage());
        }
    }
}
